﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IssuedItemReturn.aspx.cs"
    Culture="en-GB" Inherits="Main_Inventory_IssuedItemReturn" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../JavaScript/Commons.js" type="text/javascript"></script>
    <link href="../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .AutoExtender
        {
            margin: 0px;
            background-color: White;
            color: windowtext;
            border: 1px solid #006699;
            line-height: 18px;
            padding: 8px;
            border-width: 1px;
            border-style: solid;
            cursor: 'default';
            height: auto;
            min-height: 10px;
            font-family: Verdana, Helvetica, Sans-Serif;
            font-size: .8em;
            font-weight: normal;
            text-align: left;
            list-style-type: none;
        }
        .AutoExtenderList
        {
            border-bottom: solid 1px #006699;
            color: Maroon;
            padding: 1px;
        }
        .AutoExtenderHighlight
        {
            color: White;
            background-color: #006699;
            padding: 1px;
        }
        #Background
        {
            position: fixed;
            top: 0px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            background-color: #E8EAEC;
            opacity: 0.5;
        }
        #Progress
        {
            position: fixed;
            top: 45%;
            margin-left: 350px;
            width: 300px;
            height: 50px;
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        function divExpandCollapse(divname) {
            var div = document.getElementById(divname);
            var img = document.getElementById('img' + divname);
            if (div.style.display == "none") {
                div.style.display = "inline";
                img.src = "../../Menu/images/minus.gif";
            }
            else {
                div.style.display = "none";
                img.src = "../../Menu/images/plus.gif";
            }
        }
    </script>
    <script type="text/javascript">
        function isNumberKey(control_id, evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode >= 47))
                return false;

            if (charCode == 46) {
                //var dotcount = document.getElementById(control_id).value.split('.').length - 1;
                //if (dotcount >= 1) {
                return false;
                //}
            }
            return true;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="scriptmgr" EnablePageMethods="true" EnablePartialRendering="true"
            runat="server">
        </asp:ScriptManager>
        <acc:heading ID="header1" runat="server" HeadingText="BackFlush Item " />
        <asp:UpdateProgress ID="prgLoadingStatus" AssociatedUpdatePanelID="UPbtngetreport"
            runat="server" DynamicLayout="true">
            <ProgressTemplate>
                <div id="Background" runat="server">
                </div>
                <div align="center" id="Progress">
                    <img src="../../Images/ajax-loader.gif" alt="progessbar" />
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <div align="center">
            <asp:Label ID="lblmsg" runat="server" Visible="false"></asp:Label>
            <asp:Panel ID="pnlslipNo" runat="server" Width="40%">
                <table width="100%" class="tablecontent" style="padding: 5px;">
                    <tr>
                        <td colspan="3" class="headtd">
                            Slip Detail
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Enter Slip No
                        </td>
                        <td>
                            <asp:TextBox ID="txtslipno" runat="server" CssClass="input" AutoPostBack="true" onKeyPress="return isNumberKey(this.id,event)"></asp:TextBox>
                            <Ajax:AutoCompleteExtender ID="ACE" runat="server" TargetControlID="txtslipno" ServiceMethod="GetSlipNo"
                                MinimumPrefixLength="1" CompletionInterval="0" EnableCaching="true" FirstRowSelected="false"
                                CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderList"
                                CompletionListHighlightedItemCssClass="AutoExtenderHighlight" ShowOnlyCurrentWordInCompletionListItem="true"
                                DelimiterCharacters=";," CompletionSetCount="20">
                            </Ajax:AutoCompleteExtender>
                        </td>
                        <td>
                            &nbsp;<asp:Button ID="btnGetDetail" runat="server" CssClass="button1" OnClick="btnGetDetail_Click"
                                Text="Slip No" OnClientClick="return CheckSlipNo();" />
                            <script type="text/javascript">
                                function CheckSlipNo() {
                                    if (document.getElementById("txtslipno").value == '') {
                                        alert("Please Enter the Slip No.");
                                        return false;
                                    }
                                }
                            </script>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
        </div>
        <br />
        <div align="center">
            <asp:UpdatePanel ID="UpdateStockreport" runat="server">
                <ContentTemplate>
                    <asp:Panel ID="pnl_Detail" runat="server" Width="99%" CssClass="tablecontent">
                        <table width="100%">
                            <tr>
                                <td style="width: 10%;">
                                    Issued Date
                                </td>
                                <td style="width: 20%;">
                                    Issued By
                                </td>
                                <td style="width: 20%;">
                                    Requested By
                                </td>
                                <td style="width: 12%;">
                                    Return Date<span class="required">*</span>
                                </td>
                                <td style="width: 18%;">
                                    Return By
                                </td>
                                <td style="width: 20%;">
                                    Returned To<span class="required">*</span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;<asp:TextBox ID="txtissuedate" CssClass="input" runat="server" Enabled="false"
                                        ForeColor="Black" Width="90%"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="TxtissuedBy" CssClass="input" runat="server" Enabled="false" ForeColor="Black"
                                        Width="95%"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="txtrequestedBy" runat="server" CssClass="input" Enabled="false"
                                        ForeColor="Black" Width="95%"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="txtRetrunDate" runat="server" CssClass="input" ForeColor="Black"
                                        Height="17px" onKeyPress="return false;" Width="80px"></asp:TextBox>
                                    <asp:ImageButton ID="btnReturnDate" runat="server" ImageUrl="~/Images/calendar.gif"
                                        Style="margin-top: 3px;" />
                                </td>
                                <td>
                                    <Ajax:CalendarExtender ID="CalIssueDate" runat="server" Format="dd/MM/yyyy" PopupButtonID="btnReturnDate"
                                        TargetControlID="txtRetrunDate">
                                    </Ajax:CalendarExtender>
                                    <asp:TextBox ID="txtRetrunBy" CssClass="input" runat="server" Style="background-color: #EBEBE4;"
                                        Height="17px" ForeColor="Black" onKeyPress="return false;" Width="95%"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="txtreturnedto" runat="server" CssClass="input" ForeColor="Black"
                                        Width="95%"></asp:TextBox>
                                    <Ajax:AutoCompleteExtender ID="ACEreturn" runat="server" TargetControlID="txtreturnedto"
                                        ServiceMethod="ReturnTo" CompletionInterval="0" CompletionListCssClass="AutoExtender"
                                        CompletionListHighlightedItemCssClass="AutoExtenderHighlight" CompletionListItemCssClass="AutoExtenderList"
                                        CompletionSetCount="20" DelimiterCharacters=";," EnableCaching="true" FirstRowSelected="false"
                                        MinimumPrefixLength="1">
                                    </Ajax:AutoCompleteExtender>
                                </td>
                            </tr>
                            <tr>
                                <td class="headtd" colspan="6">
                                    Issued Item Detail
                                </td>
                            </tr>
                        </table>
                        <asp:HiddenField ID="hidIssuedItemDetail" runat="server" />
                        <table width="100%" cellpadding="1" cellspacing="0" id="tbldetail" runat="server"
                            class="tablecontent">
                            <tr>
                                <td style="width: 10%; text-align: center; border: 1px solid gray;">
                                    Item Code
                                </td>
                                <td style="width: 20%; text-align: center; border: 1px solid gray;">
                                    Item Name
                                </td>
                                <td>
                                </td>
                                <td style="width: 10%; text-align: center; border: 1px solid gray;">
                                    RO#
                                </td>
                                <td style="width: 15%; text-align: center; border: 1px solid gray;">
                                    Customer
                                </td>
                                <td style="width: 15%; text-align: center; border: 1px solid gray;">
                                    Project Name
                                </td>
                                <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                    Issued Qty
                                </td>
                                <td style="width: 7%; text-align: center; border: 1px solid gray;">
                                    Prev Return
                                </td>
                                <td style="width: 8%; text-align: center; border: 1px solid gray;">
                                    Balance
                                </td>
                                <td style="width: 8%; text-align: center; border: 1px solid gray;">
                                    Return Qty
                                </td>
                            </tr>
                        </table>
                        <table>
                            <tr>
                                <td>
                                    <asp:UpdatePanel ID="UPbtngetreport" runat="server">
                                        <ContentTemplate>
                                            <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="button1" OnClick="btnSave_Click"
                                                OnClientClick="return CheckData();" />
                                            &nbsp;
                                            <script type="text/javascript">
                                                function CheckValue(RowId) {
                                                    var ReturnQty = document.getElementById("txtReturnQty" + RowId).value;
                                                    if (ReturnQty <= 0) {
                                                        alert("Please Check the Return Qty.");
                                                        document.getElementById("txtReturnQty" + RowId).value = "0";
                                                        return false;
                                                    }
                                                    var BalanceQty = document.getElementById("txtBalance" + RowId).value;
                                                    if (ReturnQty != "" && BalanceQty != "") {
                                                        if (Number(ReturnQty) > Number(BalanceQty)) {
                                                            alert("You cannot enter Return qty greater than Balanced qty. ");
                                                            document.getElementById("txtReturnQty" + RowId).value = '';
                                                            document.getElementById("txtReturnQty" + RowId).focus();
                                                            return false;
                                                        }
                                                    }
                                                }
                                                function CheckData() {
                                                    if (document.getElementById("txtRetrunDate").value == '') {
                                                        alert("Please Enter Return Date. ");
                                                        document.getElementById("txtRetrunDate").focus();
                                                        return false;
                                                    }
                                                    else if (document.getElementById("txtRetrunBy").value == '') {
                                                        alert("Enter Return by Detail.");
                                                        document.getElementById("txtRetrunBy").focus();
                                                        return false;
                                                    }
                                                    else if (document.getElementById("txtreturnedto").value == '') {
                                                        alert("Enter Return To Detail. ");
                                                        document.getElementById("txtreturnedto").value = '';
                                                        document.getElementById("txtreturnedto").focus();
                                                        return false;
                                                    }
                                                    var row = document.getElementById("hidIssuedItemDetail").value;
                                                    var set = 0;
                                                    for (var i = 1; i <= row; i++) {
                                                        if (document.getElementById("txtReturnQty" + i).value == '') {
                                                            set = set + 1;
                                                        }
                                                        if (set == row) {
                                                            alert("Return Qty Cannot be left blank.");
                                                            document.getElementById("txtReturnQty1").focus();
                                                            return false;
                                                        }
                                                    }
                                                    document.getElementById("btnSave").enabled = false;
                                                }
                                            </script>
                                            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button1" OnClick="btnCancel_Click" />
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        <div align="center" style="width: 95%; margin-left: 20px;">
            <asp:Panel ID="pnldetailview" runat="server">
                <asp:GridView ID="grdView" runat="server" Width="100%" CssClass="gridview" DataKeyNames="RETURNID"
                    AutoGenerateColumns="false" OnRowDataBound="grdView_RowDataBound">
                    <Columns>
                        <asp:TemplateField HeaderText="S No">
                            <ItemTemplate>
                                <%#Container.DataItemIndex + 1 %>
                                <a href="Javascript:divExpandCollapse('div<%# Eval("RETURNID") %>');">
                                    <img id="imgdiv<%#Eval("RETURNID") %>" width="9px" border="0" src="../../Menu/images/plus.gif" />
                                </a>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="SLIPNO" HeaderText="Slip No" />
                        <asp:BoundField DataField="ISSUEDATE" HeaderText="Issued Date" DataFormatString="{0:dd/MM/yyyy}" />
                        <asp:BoundField DataField="ISSUEBY" HeaderText="Issued By" />
                        <asp:BoundField DataField="REQUESTEDBY" HeaderText="Requested By" />
                        <asp:BoundField DataField="RETURNDATE" HeaderText="Return Date" DataFormatString="{0:dd/MM/yyyy}" />
                        <asp:BoundField DataField="RETURNBY" HeaderText="Return By" />
                        <asp:BoundField DataField="RETURNTO" HeaderText="Return To" />
                        <asp:TemplateField>
                            <ItemTemplate>
                                <tr>
                                    <td colspan="100%">
                                        <div id="div<%# Eval("RETURNID") %>" style="display: none; position: relative; left: 15px;
                                            overflow: auto">
                                            <asp:GridView ID="gvItemRetrunChild" runat="server" CssClass="gridview" AutoGenerateColumns="false"
                                                Width="96%">
                                                <Columns>
                                                    <asp:TemplateField HeaderText="S.No">
                                                        <ItemTemplate>
                                                            <%# Container.DataItemIndex+1 %>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField HeaderText="Item Code" DataField="ItemCode" />
                                                    <asp:BoundField HeaderText="Item Desc" DataField="ItemDesc" />
                                                    <asp:BoundField HeaderText="Ro#" DataField="RO" />
                                                    <asp:BoundField HeaderText="Customer" DataField="CustomerName" />
                                                    <asp:BoundField HeaderText="Project Name" DataField="projectname" />
                                                    <asp:BoundField HeaderText="Issued Qty" DataField="IssueQty" ItemStyle-HorizontalAlign="Right" />
                                                    <asp:BoundField HeaderText="Return Qty" DataField="ReturnQTY" ItemStyle-HorizontalAlign="Right" />
                                                </Columns>
                                            </asp:GridView>
                                        </div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </asp:Panel>
        </div>
    </div>
    </form>
</body>
</html>
